package com.yztc.xiami_app.ui.shopcart.presenter;

import com.yztc.xiami_app.bean.shopcart.ShopCart;
import com.yztc.xiami_app.ui.shopcart.interfaces.IGetShopCartDataListener;
import com.yztc.xiami_app.ui.shopcart.model.IShopCartModel;
import com.yztc.xiami_app.ui.shopcart.model.ShopCartModelImpl;
import com.yztc.xiami_app.ui.shopcart.view.IShopCartView;

import java.util.List;

import cn.bmob.v3.BmobObject;

/**
 * Created by 周旭 on 2016/11/21.
 * <p>
 * "获取购物车"商品信息的Presenter层的实现类
 */

public class ShopCartPresenterImpl implements IShopCartPresenter {

    private IShopCartModel mShopCartModel;
    private IShopCartView mShopCartView;
    //Bmob云中购物车查询的回调接口
    private IGetShopCartDataListener listener = new IGetShopCartDataListener() {
        @Override
        public void setData(List<ShopCart> shopCartList) {
            //成功获取，调用View的方法把数据给UI
            mShopCartView.getShopCartData(shopCartList);
        }

        @Override
        public void setDeleteResult(boolean flag) {
            //获取删除选中商品是否成功的结果，如果为true，表示删除成功
            mShopCartView.showDeleteGoodsResult(flag);
        }
    };


    public ShopCartPresenterImpl(IShopCartView mShopCartView) {
        mShopCartModel = new ShopCartModelImpl(listener);
        this.mShopCartView = mShopCartView;
    }

    //获取Bmob云中的数据库中的购物车的商品信息的列表
    @Override
    public void getShopCart() {
        //获取到Bmob云中的购物车的商品信息
        mShopCartModel.getShopCartData();
    }

    /**
     * 从Bmob云删除选中的商品
     *
     * @param shopCartList:选中的要删除的商品的集合
     */
    @Override
    public void deleteGoods(List<BmobObject> shopCartList) {
        //删除选中的商品
        mShopCartModel.deleteGoods(shopCartList);
    }
}
